package hn.cch.spring.context.boot;

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;

@SpringBootApplication
public class ContextApplication {

    public static void main(String[] args) {

        ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder(ContextApplication.class)
            .web(WebApplicationType.NONE)
            .run(args);
        // BeanLifeCycle beanLifeCycle = applicationContext.getBean(BeanLifeCycle.class);
        InitImpl initImpl = applicationContext.getBean(InitImpl.class);
        DestroyImpl destroyImpl = applicationContext.getBean(DestroyImpl.class);
        applicationContext.close();
    }

    @Scope
    @Bean(initMethod = "initMethod")
    public InitImpl initBean() {
        return new InitImpl();
    }

    @Bean(destroyMethod = "destroyMethod")
    public DestroyImpl destroyBean() {
        return new DestroyImpl();
    }
}
